# Maintainer: Green0Photon <green0photon AT gmail DOT com>

pkgname=task
pkgver=2.5.1
pkgrel=3
pkgdesc="A command-line todo list manager"
arch=('i686' 'x86_64')
url="https://taskwarrior.org/"
license=("MIT")
depends=("gcc-libs"
         "libgnutls"
         "libutil-linux"
         "libhogweed" # for some reason, didn't install with libgnutls
)
makedepends=("git" # 'msys2-w32api-headers>=5.0.0.4624' 'msys2-w32api-runtime'
             "gcc"
             "make"
             "cmake"
             "libgnutls-devel"
             "libutil-linux-devel"
)
# AUR packages had an odd colon notation
# The comments were within the quotes so pacman knew about it
optdepends=("bash-completion" # for bash completion
            "python" # for python export addon
            "ruby" # for ruby export addon
            "perl" # for perl export addon
            "perl-JSON" # for perl export addon
            "rsync" # synchronisation via rsync
            "curl" # synchronisation via http(s)/ftp
            "openssh" # synchronisation via ssh
)
checkdepends=("python" # for tests
              "bash" # for tests
)

# This has symlink problems with files missing
#source=("https://taskwarrior.org/download/${pkgname}-${pkgver}.tar.gz")
#sha256sums=("d87bcee58106eb8a79b850e9abc153d98b79e00d50eade0d63917154984f2a15")

source=("${pkgname}-s${pkgver}.tar.gz"::"https://github.com/taskwarrior/${pkgname}/archive/s${pkgver}.tar.gz")
sha256sums=("30a6253aa5de2f339def58150edcf1d7c1a302875f30f9b31160eaaf2303e978")
noextract=(${pkgname}-s${pkgver}.tar.gz)

prepare() {
  [[ -d ${srcdir}/${pkgname}-s${pkgver} ]] && rm -rf ${srcdir}/${pkgname}-s${pkgver}
  tar -xzf ${srcdir}/${pkgname}-s${pkgver}.tar.gz -C $srcdir || true
}

build() {
  cd "${srcdir}/${pkgname}-s${pkgver}"
#  ls "/usr/include/sys"
#  pacman -Q
  msg "Starting cmake..."
  cmake -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX=/usr .

  sed -i -r 's/-luuid/-luuid.dll/' src/CMakeFiles/task_executable.dir/link.txt
  sed -i -r 's/-luuid/-luuid.dll/' src/CMakeFiles/calc_executable.dir/link.txt
  sed -i -r 's/-luuid/-luuid.dll/' src/CMakeFiles/lex_executable.dir/link.txt

  msg "Starting make..."
  make
}

package() {
  cd "${srcdir}/${pkgname}-s${pkgver}"
  make DESTDIR=$pkgdir install

  # Note that we rename the bash completion script for bash-completion > 1.99, until upstream does so.
  install -Dm644 "$pkgdir/usr/share/doc/task/scripts/bash/task.sh" "$pkgdir/usr/share/bash-completion/completions/task"
  install -Dm644 "$pkgdir/usr/share/doc/task/scripts/fish/task.fish" "$pkgdir/usr/share/fish/completions/task.fish"
  install -Dm644 "$pkgdir/usr/share/doc/task/scripts/zsh/_task" "$pkgdir/usr/share/zsh/site-functions/_task"

  install -Dm644 "$pkgdir/usr/share/doc/task/scripts/vim/ftdetect/task.vim" "$pkgdir/usr/share/vim/vimfiles/ftdetect/task.vim"
  install -Dm644 "$pkgdir/usr/share/doc/task/scripts/vim/syntax/taskdata.vim" "$pkgdir/usr/share/vim/vimfiles/syntax/taskdata.vim"
  install -Dm644 "$pkgdir/usr/share/doc/task/scripts/vim/syntax/taskedit.vim" "$pkgdir/usr/share/vim/vimfiles/syntax/taskedit.vim"
  install -Dm644 "$pkgdir/usr/share/doc/task/scripts/vim/syntax/taskrc.vim" "$pkgdir/usr/share/vim/vimfiles/syntax/taskrc.vim"

  install -Dm644 "$srcdir/$pkgname-s$pkgver/LICENSE" "$pkgdir/usr/share/licenses/task/LICENSE"
}

check() {
  cd "${srcdir}/${pkgname}-s${pkgver}/test"

  msg "Starting make for testing..."
  make

  msg "Running tests (Please be patient)..."
  ./run_all || true
  msg "Results:"
  ./python problems || true
}
